package com.jy.adscm.zltx.controller;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.jy.adscm.exception.AdscmSystemException;
import com.jy.adscm.support.SimpleCoreResponse;
import com.jy.adscm.zltx.bean.JyDrawingList;
import com.jy.adscm.zltx.bean.JyDrawingRelation;
import com.jy.adscm.zltx.service.JyDrawingRelationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yyy
 * @since 2019-02-21
 */
@RestController
@RequestMapping("/adscm/zltx/jyDrawingRelation")
public class JyDrawingRelationController {

      @Autowired
    JyDrawingRelationService jyDrawingRelationService;
    @RequestMapping("/insert")
    public SimpleCoreResponse insert( HttpServletRequest request) throws AdscmSystemException, IOException {
        String jyDrawingRelationstr = request.getParameter("jyDrawingRelations");
        ObjectMapper objectMapper=new ObjectMapper();
        JavaType jt = objectMapper.getTypeFactory().constructParametricType(ArrayList.class, JyDrawingRelation.class);
        List<JyDrawingRelation> jyDrawingRelations = objectMapper.readValue(jyDrawingRelationstr, jt);
        return new SimpleCoreResponse("200","新增成功" ,jyDrawingRelationService.insertJyDrawingRelations(jyDrawingRelations));
    }
    @RequestMapping("/select/{id}")
    public SimpleCoreResponse select( @PathVariable Integer id, HttpServletRequest request) throws AdscmSystemException {
        Wrapper<JyDrawingRelation> wrapper =new EntityWrapper<>();
        wrapper.eq("drawing_id",id);
        return new SimpleCoreResponse("200","查询成功" ,jyDrawingRelationService.selectList(wrapper));
    }

}

